/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
jQuery.noConflict();
var aeRequest;
var action;
var ajxUrl= "";
var userid;
var username;
var password;
var type;
var shiptype;
var contactperson;
var designation;
var city;
var address;
var email;
var telephone;
var mobile;
var faxnumber;
var description;
var experience;
var userstatus;
var IdArr = new Array();
var compound = /^[0-9\s]+$/gi;
var rowId;
var flag;
var rowCount;

function createXmlHttpRequestObject() {
    var ro;
    var browser = navigator.appName;
    // Need to determine IE7 and not do this.
    if (browser == "Microsoft Internet Explorer") {
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else {
        ro = new XMLHttpRequest();
    }
    return ro;
}

function createResponseXML(textXML) {
    // code for IE
    if (window.ActiveXObject) {
        var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
        xmlDoc.async = "false";
        xmlDoc.loadXML(textXML);
        return xmlDoc;
    }
    // code for Mozilla, Firefox, Opera, etc.
    else {
        var parser = new DOMParser();
        var xmlDoc = parser.parseFromString(textXML, "text/xml");
        return xmlDoc;
    }
}

function updateUser(userid,type,paymenttype,password,username,shiptype,contactperson,designation,address,city,mobile,telephone,faxnumber,email,experience,description,userstatus,action){
    var url = '/RadioCabsProject-war/UserRadioCabServlet?userid=' +userid+ '&type=' +type+
    '&paymenttype=' +paymenttype+ '&username=' +username+
    '&password=' +password+ '&shiptype=' +shiptype+ '&contactperson=' +contactperson+
    '&designation='  +designation+ '&address=' +address+ '&city=' +city+
    '&mobile=' +mobile+ '&telephone=' +telephone+ '&faxnumber=' +faxnumber+
    '&email=' +email+ '&experience=' +experience+ '&description=' +description+
    '&userstatus=' +userstatus+ '&action=add';
    //alert(url);
    aeRequest = createXmlHttpRequestObject();
    aeRequest.open("POST", url, true);
    aeRequest.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    aeRequest.onreadystatechange = finishUpdate;
    aeRequest.send(null);
}

function finishLogout(){
    if(aeRequest.readyState==4){
        if(aeRequest.status == 200){
            window.location.href="login.jsp";
        }
    }
}

function finishUpdate(){
    if(aeRequest.readyState==4){
        if(aeRequest.status == 200){
            var response = createResponseXML(aeRequest.responseText);
            var result = response.getElementsByTagName("result")[0].firstChild.nodeValue;
            if (result == "success") {
                //alert("update/edit successful");
                //window.location.href = "regresult.jsp?type="+type+'&username='+username +'&password='+password;
                jQuery("#typeHide").val(type);
                jQuery("#usernameHide").val(username);
                jQuery("#passwordHide").val(password);
                jQuery("#Hideform").submit();
            }else{
        //alert("update/edit failed");
        }
        }
    }
}

function randomString() {
    var chars = "0123456789";
    var string_length = 6;
    var randomstring = '';
    for (var i=0; i<string_length; i++) {
        var rnum = Math.floor(Math.random() * chars.length);
        randomstring += chars.substring(rnum,rnum+1);
    }
    return randomstring;
}
String.prototype.trim = function()
{
    var trimmed = this.replace(/^\s+|\s+$/g, '') ;
    return trimmed;
};
jQuery(document).ready(function() {
    jQuery("#btnSubmitListing").live('click',function(){
        userid = "1";
        username = jQuery("#txtCompanyName").val();
        password = jQuery("#txtCompanyPass").val();
        contactperson = jQuery("#txtContact").val();
        designation = jQuery("#txtComDesign").val();
        address = jQuery("#txtComAdd").val();
        mobile = jQuery("#txtComMobile").val();
        telephone = jQuery("#txtComTele").val();
        faxnumber = jQuery("#txtComFax").val();
        email = jQuery("#txtComEmail").val();
        shiptype = jQuery("#member-type").val();
        paymenttype = jQuery("#payment-type-listing").val();
        city = jQuery("#txtComCity").val();
        experience = "";
        description = "";
        type = "7";
        userstatus = "false";
        if(checkvalidateListingForm()){
            updateUser(userid, type, paymenttype, password, username, shiptype, contactperson, designation, address, city, mobile, telephone, faxnumber, email, experience, description, userstatus, action)
        }
    });

    jQuery("#btnResetListing").live('click',function(){
        jQuery("#txtCompanyName").val("");
        jQuery("#txtCompanyPass").val("");
        jQuery("#txtContact").val("");
        jQuery("#txtComDesign").val("");
        jQuery("#txtComAdd").val("");
        jQuery("#txtComMobile").val("");
        jQuery("#txtComTele").val("");
        jQuery("#txtComFax").val("");
        jQuery("#txtComEmail").val("");
        jQuery("#member-type").val("0");
        jQuery("#payment-type-listing").val("0");
    });

    jQuery("#btnSubmitDriver").live('click',function(){
        userid = "1";
        username = jQuery("#txtDName").val();
        password = jQuery("#txtDPass").val();
        contactperson = jQuery("#txtDContact").val();
        address = jQuery("#txtDAdd").val();
        city = jQuery("#txtDCity").val();
        mobile = jQuery("#txtDMobile").val();
        telephone = jQuery("#txtDTele").val();
        email = jQuery("#txtDEmail").val();
        experience = jQuery("#txtDExperience").val();
        description = jQuery("#txtDDescription").val();
        paymenttype = jQuery("#payment-type-driver").val();
        type = "8";
        userstatus = "false";
        shiptype = "";
        designation = "";
        faxnumber = "";
        if(checkvalidateDriverForm()){
            updateUser(userid, type, paymenttype, password, username, shiptype, contactperson, designation, address, city, mobile, telephone, faxnumber, email, experience, description, userstatus, action)
        }
    });

    jQuery("#btnResetDriver").live('click',function(){
        jQuery("#txtDName").val("");
        jQuery("#txtDPass").val("");
        jQuery("#txtDContact").val("");
        jQuery("#txtDAdd").val("");
        jQuery("#txtDCity").val("");
        jQuery("#txtDMobile").val("");
        jQuery("#txtDTele").val("");
        jQuery("#txtDEmail").val("");
        jQuery("#txtDExperience").val("");
        jQuery("#txtDDescription").val("");
        jQuery("#payment-type-driver").val("0");
    });

    jQuery("#btnSubmitAd").live('click',function(){
        userid = "1";
        username = jQuery("#txtAdverName").val();
        designation = jQuery("#txtAdverDesign").val();
        address = jQuery("#txtAdverAdd").val();
        mobile = jQuery("#txtAdverMobile").val();
        telephone = jQuery("#txtAdverTele").val();
        faxnumber = jQuery("#txtAdverFax").val();
        email = jQuery("#txtAdverEmail").val();
        description = jQuery("#txtAdverDescription").val();
        paymenttype = jQuery("#payment-type-advertise").val();
        type = "9";
        userstatus = "false";
        if(checkvalidateADVForm()){
            updateUser(userid, type, paymenttype, password, username, shiptype, contactperson, designation, address, city, mobile, telephone, faxnumber, email, experience, description, userstatus, action)
        }
    });

    jQuery("#btnResetAd").live('click',function(){
        jQuery("#txtAdverName").val("");
        jQuery("#txtAdverDesign").val("");
        jQuery("#txtAdverAdd").val("");
        jQuery("#txtAdverMobile").val("");
        jQuery("#txtAdverTele").val("");
        jQuery("#txtAdverFax").val("");
        jQuery("#txtAdverEmail").val("");
        jQuery("#txtAdverDescription").val("");
        jQuery("#payment-type-advertise").val("0");
    });
});




